/*
 * Copyright (c)  2015~2020, xforceplus
 * All rights reserved.
 * Project:datacare-orm
 * Id: SqlTemplateResource.java   2020-09-28 23-47-47
 * Author: Evan
 */
package cn.datacare.orm.engine;


import cn.datacare.orm.loader.SQLLoader;
import cn.datacare.orm.source.SQLSource;
import org.beetl.core.Resource;
import org.beetl.core.ResourceLoader;

import java.io.Reader;
import java.io.StringReader;

/**
 * <p>
 * Title:
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Copyright: 2015~2020
 * </p>
 * <p>
 * Company/Department: xforceplus
 * </p>
 *
 * @author Evan
 * <b>Creation Time:</b> 2020-09-28 23-47-47
 * @since V1.0
 */
public class SqlTemplateResource extends Resource {


    private SQLSource source;


    /***
     * 构建函数
     * @param id
     * @param loader
     * @param source
     */
    public SqlTemplateResource(String id, ResourceLoader loader, SQLSource source) {
        super(id, loader);
        this.source = source;
    }

    /**
     * 打开一个新的Reader
     *
     * @return
     */
    @Override
    public Reader openReader() {
        return new StringReader(source.getTemplate());
    }

    /**
     * 检测资源是否改变
     *
     * @return
     */
    @Override
    public boolean isModified() {
        return false;
    }

    public String getTemplate() {
        return source.getTemplate();
    }

    public int getLine() {
        return source.getLine();
    }
}
